package com.lin.controller;


import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.lin.commons.Result;
import com.lin.config.AlipayConfig;
import com.lin.entity.UserBalance;
import com.lin.service.UserBalanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 林伟鸿
 * @since 2021-11-24
 */
@RestController
@RequestMapping("/userBalance")
@CrossOrigin
@Slf4j
public class UserBalanceController {

    @Autowired
    UserBalanceService userBalanceService;



    @GetMapping("/findBalance")
    public Result findBalance(String userId) {
        return Result.success(userBalanceService.getById(Integer.parseInt(userId)).getMoney());
    }

    @GetMapping("/pay")
//    @ResponseBody
    public Result pay(String out_trade_no,String subject,String total_amount,String product_code,String userId) throws AlipayApiException {
        String body = userBalanceService.pay(out_trade_no, subject, total_amount, product_code,userId);
        return Result.success(body);

    }



}

